<?php
namespace app\api\controller\welfare;

use app\api\controller\Controller;
use think\facade\Cache;
use think\facade\Db;

class Welfare extends Controller
{
    //获取福利列表，交易数据统计
    public function get_list()
    {
        $model = new \app\shop\model\welfare\Welfares();
        $list = $model->with(['image'])->withCount(['welfare' => 'welfare_count'])
            ->where(array('is_delete'=>0))
            ->select();
        return $this->renderSuccess('', [
            'list' => $list
        ]);
    }

    public function get_user_welfare($welfare_id='')
    {
        $user = $this->getUser();
        $model = new \app\shop\model\welfare\Welfare();
        $where = array();
        if($welfare_id){
            $where[] = ['type','=',$welfare_id];
        }
        $where[] = ['is_delete','=',0];
        $where[] = ['user_id','=',$user['user_id']];
        $list = $model
            //->field('id,welfare_name,')
            ->with(['welfares'])->where($where)->paginate($this->postData(), false, [
            'query' => request()->request()
        ]);

        return $this->renderSuccess('', [
            'list' => $list
        ]);

    }
}